package org.mybatis.spring;

import com.kevin.mapper.UserMapper;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class KevinFactoryBean implements FactoryBean {

    private Class mapperClass;

    public KevinFactoryBean(Class mapperClass) {
        this.mapperClass = mapperClass;
    }

    public Object getObject() throws Exception {
//        Person person = new Person();

        Object instance = Proxy.newProxyInstance(KevinFactoryBean.class.getClassLoader(), new Class[]{mapperClass}, new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println(method.getName());
                return null;
            }
        });
        return instance;
    }

    public Class<?> getObjectType() {
        return mapperClass;
    }
}
